package com.lhc.eureka_client.serviceImpl;

import com.lhc.eureka_client.service.HelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName HelloServiceImpl
 * @Description:
 * @Author: asus
 * @CreateDate: 2020-12-24 10:55
 * @UpdateUser: asus
 * @UpdateDate: 2020-12-24 10:55
 * @UpdateRemark:
 * @Version: 1.0
 */
@Service
public class HelloServiceImpl implements HelloService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "HiError")
    public String hiService(String str) {
        //Ribbon 只能识别服务名称，由于注册到Eureka上服务名称为大写，所以这里写大写
        //Ribbon 不能识别_  可以识别-
        String ulr = "http://EUREKACLIENT/eureka/SysHello?str=";
        return restTemplate.getForObject(ulr+str,String.class);
    }

    public String HiError(String str){
        return "Sorry,"+str+",这是降级服务！！！";
    }

}
